package ru.hh.school;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;


public class UserManager {
    private final Map<String, User> usersOnline;

    public UserManager() {
        usersOnline = new HashMap<String, User>();
    }

    public synchronized void addUser(User user) {
        usersOnline.put(user.getLogin(), user);
    }


    public synchronized User getUserByLogin(String login) {
        if (!usersOnline.containsKey(login)) {
            return null;
        }
        return usersOnline.get(login);
    }

    public synchronized void deleteUser(User user) {
        usersOnline.remove(user.getLogin());
    }

    public synchronized Collection<User> getUsers() {
        return java.util.Collections.unmodifiableCollection(usersOnline.values());
    }
}
